<?php /*a:2:{s:54:"F:\CaOadmin\application\admin\view\Admin\roleform.html";i:1569385476;s:37:"../application/admin/view/layout.html";i:1569485205;}*/ ?>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">
    <title><?php echo htmlentities($title); ?></title>

    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->

    <link rel="shortcut icon" href="favicon.ico">
    <link href="<?php echo staticResource('css/bootstrap.min.css?v=3.3.6'); ?>" rel="stylesheet">
    <link href="<?php echo staticResource('css/font-awesome.min.css?v=4.4.0'); ?>" rel="stylesheet">
    
<link href="<?php echo staticResource('css/plugins/iCheck/custom.css'); ?>" rel="stylesheet">

    <link href="<?php echo staticResource('css/animate.css'); ?>" rel="stylesheet">
    <link href="<?php echo staticResource('css/style.css?v=4.1.0'); ?>" rel="stylesheet">
    <link href="<?php echo staticResource('extend/common.css'); ?>" rel="stylesheet">
</head>

<body class="fixed-sidebar full-height-layout gray-bg">

<div class="wrapper wrapper-content animated fadeInRight">

  <div class="row">
    <div class="col-sm-12">
      <div class="ibox float-e-margins">
        <div class="ibox-content">
          <form method="post" class="form-horizontal" id="main-form">

            <?php if(!empty($data)): ?>
            <div class="form-group">
              <label class="col-sm-2 control-label">ID</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" value="<?php echo htmlentities($data['id']); ?>" name="id" readonly>
              </div>
            </div>
            <?php endif; ?>

            <div class="form-group">
              <label class="col-sm-2 control-label">角色名</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" value="<?php echo empty($data) ? '' : $data['name']; ?>" name="name">
              </div>
            </div>

            <div class="form-group">
              <label class="col-sm-2 control-label">权限列表</label>
              <div class="col-sm-10">
                <!--权限列表-->
                <div class="dd" id="nestable">
                  <ol class="dd-list">
                    <?php foreach($auth_list as $k => $auth): ?>
                    <li class="dd-item dd-nodrag" data-id="0">
                      <div class="dd-handle">
                        <input type="checkbox" class="i-checks" name="auth_list[]" value="0" a-id="{0}">
                        <?php echo htmlentities($auth_title[$k]); ?>
                      </div>
                      <ol class="dd-list">
                        <?php foreach($auth as $au): ?>
                        <li class="dd-item" data-id="<?php echo htmlentities($au['id']); ?>">
                          <div class="dd-handle">
                            <input type="checkbox" class="i-checks" name="auth_list[]" value="<?php echo htmlentities($au['id']); ?>" a-id="<?php echo htmlentities($au['id']); ?>">
                            <?php echo htmlentities($au['name']); ?>
                          </div>
                          <ol class="dd-list">
                            <?php foreach($au['item'] as $v): ?>
                            <li class="dd-item" data-id="<?php echo htmlentities($v['id']); ?>">
                              <div class="dd-handle">
                                <input type="checkbox" class="i-checks" name="auth_list[]" value="<?php echo htmlentities($v['id']); ?>" a-id="<?php echo htmlentities($v['id']); ?>">
                                <?php echo htmlentities($v['name']); ?>
                              </div>
                            </li>
                            <?php endforeach; ?>
                          </ol>
                        </li>
                        <?php endforeach; ?>
                      </ol>
                    </li>
                    <?php endforeach; ?>
                  </ol>
                </div>
              </div>
            </div>

            <div class="form-group">
              <div class="col-sm-4 col-sm-offset-2">
                <button class="btn btn-primary" type="button" id="sub">保存</button>
              </div>
            </div>

          </form>
        </div>
      </div>
    </div>
  </div>

</div>


<!-- 全局js -->
<script src="<?php echo staticResource('js/jquery.min.js?v=2.1.4'); ?>"></script>
<script src="<?php echo staticResource('js/bootstrap.min.js?v=3.3.6'); ?>"></script>
<script src="<?php echo staticResource('js/plugins/metisMenu/jquery.metisMenu.js'); ?>"></script>
<script src="<?php echo staticResource('js/plugins/slimscroll/jquery.slimscroll.min.js'); ?>"></script>
<script src="<?php echo staticResource('js/plugins/layer/layer.min.js'); ?>"></script>
<script src="<?php echo staticResource('extend/common.js'); ?>"></script>

<!-- 自定义js -->

<!-- Nestable List -->
<script src="<?php echo staticResource('js/plugins/nestable/jquery.nestable.js'); ?>"></script>
<!--选择框JS-->
<script src="<?php echo staticResource('js/plugins/iCheck/icheck.min.js'); ?>"></script>
<script>
    $(function () {
        // 回显权限
        var own_auth = <?php echo arr2Str($data['auth_list']); ?>;
        if(own_auth.length > 0) {
            $("input[name='auth_list[]']:checkbox").each(function() {
                if (own_auth.indexOf(parseInt($(this).attr('a-id'))) > -1) {
                    $(this).iCheck('check')
                }
            });
        }
        // 当子选项有勾选，则勾选父选项
        $("input[name='auth_list[]']:checkbox").each(function() {
            if (true == $(this).is(':checked')) {
                $(this).parents('ol').eq(0).prev().find('.i-checks').iCheck('check')
            }
        });
        $("input[name='auth_list[]']:checkbox").each(function() {
            if (true == $(this).is(':checked')) {
                $(this).parents('ol').eq(0).prev().find('.i-checks').iCheck('check')
            }
        });

        // 提交表单
        $('#sub').click(function () {
            var auth_list = [];
            $("input[name='auth_list[]']:checkbox").each(function() {
                if (true == $(this).is(':checked') && $(this).val() != 0) {
                    auth_list.push(parseInt($(this).val()))
                }
            });
            if(auth_list.length == 0) {
                layer.msg('请选择权限');
                return;
            }

            http_post(
                "<?php echo url('admin/role/save'); ?>",
                $('#main-form').serialize(),
                function (res) {
                    layer.msg('保存成功',{icon:1},function () {
                        parent.location.reload();
                    })
                }
            )
            return false;
        })

        // 权限列表
        var updateOutput = function (e) {
            var list = e.length ? e : $(e.target),
                output = list.data('output');
            if (window.JSON) {
                output.val(window.JSON.stringify(list.nestable('serialize'))); //, null, 2));
            } else {
                output.val('浏览器不支持');
            }
        };

        // activate Nestable for list 2
        $('#nestable').nestable({
            group: 1,
            allowDrag:false
        }).on('change', updateOutput);

        updateOutput($('#nestable').data('output', $('#nestable2-output')));

        // 选择框
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green',
        });

        // 全选或全不选权限
        $('#nestable input').on('ifChecked ifUnchecked', function(e){
            if(e.type == 'ifChecked') {
                $(this).parents('.dd-item').eq(0).find('.i-checks').iCheck('check')
            }else{
                $(this).parents('.dd-item').eq(0).find('.i-checks').iCheck('uncheck')
            }
        });

    })
</script>


</body>

</html>
